import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '图片与ICON示例',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: ImageIconDemo(),
    );
  }
}

class ImageIconDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // 本地图片路径需在 pubspec.yaml 中正确配置
    // 网络图片可直接使用
    return Scaffold(
      appBar: AppBar(title: Text('图片与ICON示例')),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            // 1. 加载本地图片
            Text('本地图片（AssetImage）:'),
            Image.asset(
              'images/avatar.png', // 请确保 pubspec.yaml 已配置
              width: 100.0,
            ),
            SizedBox(height: 20),
            // 2. 加载网络图片
            Text('网络图片（NetworkImage）:'),
            Image.network(
              'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl.jpg',
              width: 100.0,
            ),
            SizedBox(height: 20),
            // 3. 图片的 fit 属性演示
            Text('图片 fit 属性演示:'),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Image.asset(
                  'images/avatar.png',
                  width: 100.0,
                  height: 50.0,
                  fit: BoxFit.fill,
                ),
                SizedBox(width: 10),
                Image.asset(
                  'images/avatar.png',
                  width: 100.0,
                  height: 50.0,
                  fit: BoxFit.contain,
                ),
                SizedBox(width: 10),
                Image.asset(
                  'images/avatar.png',
                  width: 100.0,
                  height: 50.0,
                  fit: BoxFit.cover,
                ),
              ],
            ),
            SizedBox(height: 20),
            // 4. Material Design ICON
            Text('Material Design ICON:'),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Icon(Icons.accessible, color: Colors.green, size: 36),
                Icon(Icons.error, color: Colors.red, size: 36),
                Icon(Icons.fingerprint, color: Colors.blue, size: 36),
              ],
            ),
            SizedBox(height: 20),
            // 5. 通过Text显示ICON（不推荐，仅演示）
            Text('通过Text显示ICON:'),
            Text(
              '\uE03e \uE237 \uE287',
              style: TextStyle(
                fontFamily: 'MaterialIcons',
                fontSize: 36.0,
                color: Colors.orange,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
